package com.algrithom.math;

/**
 * 1267 统计参与通信的服务器
 */
public class Solution4 {
    
    int countServers(int[][] grid){
        int m = grid.length;
        int n = grid[0].length;
        int[] mCount = new int[m];
        int[] nCount = new int[n];
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                if (grid[i][j] == 1) {
                    ++mCount[i];
                    ++nCount[j];
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < n; ++j) {
                if (grid[i][j] == 1 && (mCount[i] > 1 || nCount[j] > 1)) {
                    ++ans;
                }
            }
        }
        return ans;
    }
}
